package com.example.administrator.mobliesafe;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;

import com.example.administrator.mobilesafe.ui.SettingItemView;
import com.example.administrator.mobilesafe.utils.BaseSetupAcitivity;

public class Setup2Activity extends BaseSetupAcitivity {
    private Button bt_srtup2_pre;
    private Button bt_srtup2_next;
    private SettingItemView bt_setup2_sim;
    private String sim;
    private TelephonyManager telephonyManager ;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setup2);
        telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
        sim = telephonyManager.getSimSerialNumber();
        bt_setup2_sim = (SettingItemView) findViewById(R.id.setup2_sim_safe);
        sharedPreferences = getSharedPreferences("config",MODE_PRIVATE);
        if(TextUtils.isEmpty(sharedPreferences.getString("sim",null))){
            bt_setup2_sim.setChecked(false);
        }else {
            bt_setup2_sim.setChecked(true);
        }
        bt_srtup2_next = (Button) findViewById(R.id.bt_setup2_next);
        bt_srtup2_pre = (Button) findViewById(R.id.bt_setup2_pre);
        bt_srtup2_pre.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                pre(v);
            }
        });
        bt_srtup2_next.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                next(v);
            }
        });
        bt_setup2_sim.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(bt_setup2_sim.isChecked()){
                    SharedPreferences.Editor editor = sharedPreferences.edit();
                    editor.putString("sim","");
                    editor.commit();
                    bt_setup2_sim.setChecked(false);
                }else {
                    SharedPreferences.Editor editor = sharedPreferences.edit();
                    editor.putString("sim",sim);
                    editor.commit();
                    bt_setup2_sim.setChecked(true);
                }
            }
        });
    }

    @Override
    public void showPre() {
        Intent intent = new Intent(Setup2Activity.this,Setup1Activity.class);
        startActivity(intent);
        finish();
        overridePendingTransition(R.anim.tran_in, R.anim.tran_out);
    }

    @Override
    public void showNext() {
        Intent intent = new Intent(Setup2Activity.this,Setup3Activity.class);
        startActivity(intent);
        finish();
        overridePendingTransition(R.anim.tran_out, R.anim.tran_in);
    }

}
